package payrechargelogic

import (
	"context"
	model "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/recharge"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RechargeUpdateOrderIdLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRechargeUpdateOrderIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeUpdateOrderIdLogic {
	return &RechargeUpdateOrderIdLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 充值保存第三方支付订单号
func (l *RechargeUpdateOrderIdLogic) RechargeUpdateOrderId(in *rpc.RechargeUpdateOrderIdRequest) (*rpc.RechargeUpdateOrderIdResponse, error) {
	var commonResp rpc.CommonResp

	err := model.NewRechargeOrderModel(l.ctx, l.svcCtx.Db).UpdateOrderId(in.OrderNo, in.OrderId)
	if err != nil {
		commonResp.Code = xerrors.DBError
		commonResp.Message = "Database operation error"
		return &rpc.RechargeUpdateOrderIdResponse{CommonResp: &commonResp}, err
	}

	return &rpc.RechargeUpdateOrderIdResponse{
		OrderNo:    in.OrderNo,
		OrderId:    in.OrderId,
		CommonResp: &commonResp,
	}, nil
}
